﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data.SqlClient;
using System.Data;
using TimKen.DataEntity;
namespace TimKen.DataAccess
{
    /// <summary>
    /// 数据访问类Order。
    /// </summary>
    public class OrderDAO
    {
        public OrderDAO()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string OrderID)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.VarChar,50)};
            parameters[0].Value = OrderID;

            int result = DbHelperSQL.RunProcedure("UP_Order_Exists", parameters, out rowsAffected);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  增加一条数据
        /// </summary>
        public void Add(Order model)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.VarChar,50),
					new SqlParameter("@OrderNo", SqlDbType.VarChar,50),
					new SqlParameter("@OrderType", SqlDbType.Int,4),
					new SqlParameter("@Creator", SqlDbType.VarChar,32),
					new SqlParameter("@CreateDate", SqlDbType.DateTime),
					new SqlParameter("@CardCode", SqlDbType.VarChar,50),
					new SqlParameter("@CustomerID", SqlDbType.Int,4),
					new SqlParameter("@BillAddress", SqlDbType.VarChar,255),
					new SqlParameter("@ShipType", SqlDbType.Int,4),
					new SqlParameter("@ShipToCode", SqlDbType.NVarChar,50),
					new SqlParameter("@ShipAddress", SqlDbType.NVarChar,255),
					new SqlParameter("@Freight", SqlDbType.Float,8),
					new SqlParameter("@Currency", SqlDbType.NVarChar,3),
					new SqlParameter("@Discount", SqlDbType.Float,8),
					new SqlParameter("@Rate", SqlDbType.Float,8),
					new SqlParameter("@TotalAmount", SqlDbType.Float,8),
					new SqlParameter("@BaseAmount", SqlDbType.Float,8),
					new SqlParameter("@TaxAmount", SqlDbType.Float,8),
					new SqlParameter("@DeliveryDate", SqlDbType.DateTime),
					new SqlParameter("@ExpectDate", SqlDbType.DateTime),
					new SqlParameter("@CloseDate", SqlDbType.DateTime),
					new SqlParameter("@Remark", SqlDbType.NVarChar,255),
					new SqlParameter("@ApproveType", SqlDbType.Int,4),
					new SqlParameter("@ApproveID", SqlDbType.VarChar,32),
					new SqlParameter("@ApproveTime", SqlDbType.DateTime),
					new SqlParameter("@CheckFlag", SqlDbType.Bit,1),
					new SqlParameter("@Confirmed", SqlDbType.Bit,1),
					new SqlParameter("@OrderStatus", SqlDbType.Int,4),
					new SqlParameter("@ContractStatus", SqlDbType.Int,4),
					new SqlParameter("@TaxClassID", SqlDbType.Int,4),
					new SqlParameter("@SalesPersonCode", SqlDbType.Int,4),
					new SqlParameter("@Country", SqlDbType.NVarChar,3),
					new SqlParameter("@Province", SqlDbType.NVarChar,100),
					new SqlParameter("@City", SqlDbType.NVarChar,100),
					new SqlParameter("@County", SqlDbType.NVarChar,100),
					new SqlParameter("@CntctCode", SqlDbType.NVarChar,11),
					new SqlParameter("@ContactPerson", SqlDbType.NVarChar,90),
					new SqlParameter("@Telephone", SqlDbType.NVarChar,20),
					new SqlParameter("@Mobile", SqlDbType.NVarChar,50),
					new SqlParameter("@Fax", SqlDbType.NVarChar,20),
					new SqlParameter("@Email", SqlDbType.NVarChar,100),
					new SqlParameter("@Address", SqlDbType.NVarChar,100),
					new SqlParameter("@MaxShipDays", SqlDbType.Int,4),
                    new SqlParameter("@BillToCode", SqlDbType.NVarChar,50),
                    new SqlParameter("@PlanDate",SqlDbType.DateTime),new SqlParameter("@ContractTerm", SqlDbType.NVarChar,4000),
        };
            parameters[0].Value = model.OrderID;
            parameters[1].Value = model.OrderNo;
            parameters[2].Value = model.OrderType;
            parameters[3].Value = model.Creator;
            parameters[4].Value = model.CreateDate;
            parameters[5].Value = model.CardCode;
            parameters[6].Value = model.CustomerID;
            parameters[7].Value = model.BillAddress;
            parameters[8].Value = model.ShipType;
            parameters[9].Value = model.ShipToCode;
            parameters[10].Value = model.ShipAddress;
            parameters[11].Value = model.Freight;
            parameters[12].Value = model.Currency;
            parameters[13].Value = model.Discount;
            parameters[14].Value = model.Rate;
            parameters[15].Value = model.TotalAmount;
            parameters[16].Value = model.BaseAmount;
            parameters[17].Value = model.TaxAmount;
            parameters[18].Value = model.DeliveryDate;
            parameters[19].Value = model.ExpectDate;
            parameters[20].Value = model.CloseDate;
            parameters[21].Value = model.Remark;
            parameters[22].Value = model.ApproveType;
            parameters[23].Value = model.ApproveID;
            parameters[24].Value = model.ApproveTime;
            parameters[25].Value = model.CheckFlag;
            parameters[26].Value = model.Confirmed;
            parameters[27].Value = model.OrderStatus;
            parameters[28].Value = model.ContractStatus;
            parameters[29].Value = model.TaxClassID;
            parameters[30].Value = model.SalesPersonCode;
            parameters[31].Value = model.Country;
            parameters[32].Value = model.Province;
            parameters[33].Value = model.City;
            parameters[34].Value = model.County;
            parameters[35].Value = model.CntctCode;
            parameters[36].Value = model.ContactPerson;
            parameters[37].Value = model.Telephone;
            parameters[38].Value = model.Mobile;
            parameters[39].Value = model.Fax;
            parameters[40].Value = model.Email;
            parameters[41].Value = model.Address;
            parameters[42].Value = model.MaxShipDays;
            parameters[43].Value = model.BillToCode;
            parameters[44].Value = model.PlanDate;
            parameters[45].Value = model.ContractTerm;

            DbHelperSQL.RunProcedure("UP_Order_ADD", parameters, out rowsAffected);
        }

        /// <summary>
        ///  更新一条数据
        /// </summary>
        public void Update(Order model)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.VarChar,50),
					new SqlParameter("@OrderNo", SqlDbType.VarChar,50),
					new SqlParameter("@OrderType", SqlDbType.Int,4),
					new SqlParameter("@Creator", SqlDbType.VarChar,32),
					new SqlParameter("@CreateDate", SqlDbType.DateTime),
					new SqlParameter("@CardCode", SqlDbType.VarChar,50),
					new SqlParameter("@CustomerID", SqlDbType.Int,4),
					new SqlParameter("@BillAddress", SqlDbType.VarChar,255),
					new SqlParameter("@ShipType", SqlDbType.Int,4),
					new SqlParameter("@ShipToCode", SqlDbType.NVarChar,50),
					new SqlParameter("@ShipAddress", SqlDbType.NVarChar,255),
					new SqlParameter("@Freight", SqlDbType.Float,8),
					new SqlParameter("@Currency", SqlDbType.NVarChar,3),
					new SqlParameter("@Discount", SqlDbType.Float,8),
					new SqlParameter("@Rate", SqlDbType.Float,8),
					new SqlParameter("@TotalAmount", SqlDbType.Float,8),
					new SqlParameter("@BaseAmount", SqlDbType.Float,8),
					new SqlParameter("@TaxAmount", SqlDbType.Float,8),
					new SqlParameter("@DeliveryDate", SqlDbType.DateTime),
					new SqlParameter("@ExpectDate", SqlDbType.DateTime),
					new SqlParameter("@CloseDate", SqlDbType.DateTime),
					new SqlParameter("@Remark", SqlDbType.NVarChar,255),
					new SqlParameter("@ApproveType", SqlDbType.Int,4),
					new SqlParameter("@ApproveID", SqlDbType.VarChar,32),
					new SqlParameter("@ApproveTime", SqlDbType.DateTime),
					new SqlParameter("@CheckFlag", SqlDbType.Bit,1),
					new SqlParameter("@Confirmed", SqlDbType.Bit,1),
					new SqlParameter("@OrderStatus", SqlDbType.Int,4),
					new SqlParameter("@ContractStatus", SqlDbType.Int,4),
					new SqlParameter("@TaxClassID", SqlDbType.Int,4),
					new SqlParameter("@SalesPersonCode", SqlDbType.Int,4),
					new SqlParameter("@Country", SqlDbType.NVarChar,3),
					new SqlParameter("@Province", SqlDbType.NVarChar,100),
					new SqlParameter("@City", SqlDbType.NVarChar,100),
					new SqlParameter("@County", SqlDbType.NVarChar,100),
					new SqlParameter("@CntctCode", SqlDbType.NVarChar,11),
					new SqlParameter("@ContactPerson", SqlDbType.NVarChar,90),
					new SqlParameter("@Telephone", SqlDbType.NVarChar,20),
					new SqlParameter("@Mobile", SqlDbType.NVarChar,50),
					new SqlParameter("@Fax", SqlDbType.NVarChar,20),
					new SqlParameter("@Email", SqlDbType.NVarChar,100),
					new SqlParameter("@Address", SqlDbType.NVarChar,100),
                    new SqlParameter("@BillToCode", SqlDbType.NVarChar,50),
					new SqlParameter("@MaxShipDays", SqlDbType.Int,4),
                   new SqlParameter("@PlanDate", SqlDbType.DateTime),
                 new SqlParameter("@ContractTerm", SqlDbType.NVarChar,4000),
                                        };
            parameters[0].Value = model.OrderID;
            parameters[1].Value = model.OrderNo;
            parameters[2].Value = model.OrderType;
            parameters[3].Value = model.Creator;
            parameters[4].Value = model.CreateDate;
            parameters[5].Value = model.CardCode;
            parameters[6].Value = model.CustomerID;
            parameters[7].Value = model.BillAddress;
            parameters[8].Value = model.ShipType;
            parameters[9].Value = model.ShipToCode;
            parameters[10].Value = model.ShipAddress;
            parameters[11].Value = model.Freight;
            parameters[12].Value = model.Currency;
            parameters[13].Value = model.Discount;
            parameters[14].Value = model.Rate;
            parameters[15].Value = model.TotalAmount;
            parameters[16].Value = model.BaseAmount;
            parameters[17].Value = model.TaxAmount;
            parameters[18].Value = model.DeliveryDate;
            parameters[19].Value = model.ExpectDate;
            parameters[20].Value = model.CloseDate;
            parameters[21].Value = model.Remark;
            parameters[22].Value = model.ApproveType;
            parameters[23].Value = model.ApproveID;
            parameters[24].Value = model.ApproveTime;
            parameters[25].Value = model.CheckFlag;
            parameters[26].Value = model.Confirmed;
            parameters[27].Value = model.OrderStatus;
            parameters[28].Value = model.ContractStatus;
            parameters[29].Value = model.TaxClassID;
            parameters[30].Value = model.SalesPersonCode;
            parameters[31].Value = model.Country;
            parameters[32].Value = model.Province;
            parameters[33].Value = model.City;
            parameters[34].Value = model.County;
            parameters[35].Value = model.CntctCode;
            parameters[36].Value = model.ContactPerson;
            parameters[37].Value = model.Telephone;
            parameters[38].Value = model.Mobile;
            parameters[39].Value = model.Fax;
            parameters[40].Value = model.Email;
            parameters[41].Value = model.Address;
            parameters[42].Value = model.BillToCode;
            parameters[43].Value = model.MaxShipDays;
            parameters[44].Value = model.PlanDate;
            parameters[45].Value = model.ContractTerm;
            DbHelperSQL.RunProcedure("UP_Order_Update", parameters, out rowsAffected);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string OrderID)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.VarChar,50)};
            parameters[0].Value = OrderID;

            DbHelperSQL.RunProcedure("UP_Order_Delete", parameters, out rowsAffected);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Order GetModel(string OrderID,int languageID)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@OrderID", SqlDbType.VarChar,50),
                    new SqlParameter("@LanguageID",SqlDbType.Int)
                                        
                                        };
            parameters[0].Value = OrderID;
            parameters[1].Value = languageID;

            TimKen.DataEntity.Order model = new TimKen.DataEntity.Order();
            DataSet ds = DbHelperSQL.RunProcedure("UP_Order_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.OrderID = ds.Tables[0].Rows[0]["OrderID"].ToString();
                model.OrderNo = ds.Tables[0].Rows[0]["OrderNo"].ToString();
                if (ds.Tables[0].Rows[0]["OrderType"].ToString() != "")
                {
                    model.OrderType = (OrderType)int.Parse(ds.Tables[0].Rows[0]["OrderType"].ToString());
                }
                model.Creator = ds.Tables[0].Rows[0]["Creator"].ToString();
                if (ds.Tables[0].Rows[0]["CreateDate"].ToString() != "")
                {
                    model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                }
                model.CardCode = ds.Tables[0].Rows[0]["CardCode"].ToString();
                if (ds.Tables[0].Rows[0]["CustomerID"].ToString() != "")
                {
                    model.CustomerID = int.Parse(ds.Tables[0].Rows[0]["CustomerID"].ToString());
                    model.CustomerForeignName = ds.Tables[0].Rows[0]["CustomerForeignName"].ToString();
                    model.CustomerName = ds.Tables[0].Rows[0]["CustomerName"].ToString();
                        
                }
                model.BillAddress = ds.Tables[0].Rows[0]["BillAddress"].ToString();
                if (ds.Tables[0].Rows[0]["ShipType"].ToString() != "")
                {
                    model.ShipType = int.Parse(ds.Tables[0].Rows[0]["ShipType"].ToString());
                }
                model.ShipToCode = ds.Tables[0].Rows[0]["ShipToCode"].ToString();
                model.BillToCode = ds.Tables[0].Rows[0]["BillToCode"].ToString();
                model.ShipAddress = ds.Tables[0].Rows[0]["ShipAddress"].ToString();
                if (ds.Tables[0].Rows[0]["Freight"].ToString() != "")
                {
                    model.Freight = decimal.Parse(ds.Tables[0].Rows[0]["Freight"].ToString());
                }
                model.Currency = ds.Tables[0].Rows[0]["Currency"].ToString();
                if (ds.Tables[0].Rows[0]["Discount"].ToString() != "")
                {
                    model.Discount = decimal.Parse(ds.Tables[0].Rows[0]["Discount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Rate"].ToString() != "")
                {
                    model.Rate = decimal.Parse(ds.Tables[0].Rows[0]["Rate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TotalAmount"].ToString() != "")
                {
                    model.TotalAmount = decimal.Parse(ds.Tables[0].Rows[0]["TotalAmount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BaseAmount"].ToString() != "")
                {
                    model.BaseAmount = decimal.Parse(ds.Tables[0].Rows[0]["BaseAmount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TaxAmount"].ToString() != "")
                {
                    model.TaxAmount = decimal.Parse(ds.Tables[0].Rows[0]["TaxAmount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DeliveryDate"].ToString() != "")
                {
                    model.DeliveryDate = DateTime.Parse(ds.Tables[0].Rows[0]["DeliveryDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ExpectDate"].ToString() != "")
                {
                    model.ExpectDate = DateTime.Parse(ds.Tables[0].Rows[0]["ExpectDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CloseDate"].ToString() != "")
                {
                    model.CloseDate = DateTime.Parse(ds.Tables[0].Rows[0]["CloseDate"].ToString());
                }
                model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                if (ds.Tables[0].Rows[0]["ApproveType"].ToString() != "")
                {
                    model.ApproveType = int.Parse(ds.Tables[0].Rows[0]["ApproveType"].ToString());
                }
                model.ApproveID = ds.Tables[0].Rows[0]["ApproveID"].ToString();
                if (ds.Tables[0].Rows[0]["ApproveTime"].ToString() != "")
                {
                    model.ApproveTime = DateTime.Parse(ds.Tables[0].Rows[0]["ApproveTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CheckFlag"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["CheckFlag"].ToString() == "1") || (ds.Tables[0].Rows[0]["CheckFlag"].ToString().ToLower() == "true"))
                    {
                        model.CheckFlag = true;
                    }
                    else
                    {
                        model.CheckFlag = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["Confirmed"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Confirmed"].ToString() == "1") || (ds.Tables[0].Rows[0]["Confirmed"].ToString().ToLower() == "true"))
                    {
                        model.Confirmed = true;
                    }
                    else
                    {
                        model.Confirmed = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["OrderStatus"].ToString() != "")
                {
                    model.OrderStatus = (OrderStatus)int.Parse(ds.Tables[0].Rows[0]["OrderStatus"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ContractStatus"].ToString() != "")
                {
                    model.ContractStatus = int.Parse(ds.Tables[0].Rows[0]["ContractStatus"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TaxClassID"].ToString() != "")
                {
                    model.TaxClassID = int.Parse(ds.Tables[0].Rows[0]["TaxClassID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SalesPersonCode"].ToString() != "")
                {
                    model.SalesPersonCode = int.Parse(ds.Tables[0].Rows[0]["SalesPersonCode"].ToString());
                }
                model.Country = ds.Tables[0].Rows[0]["Country"].ToString();
                model.Province = ds.Tables[0].Rows[0]["Province"].ToString();
                model.City = ds.Tables[0].Rows[0]["City"].ToString();
                model.County = ds.Tables[0].Rows[0]["County"].ToString();
                model.CntctCode = ds.Tables[0].Rows[0]["CntctCode"].ToString();
                model.ContactPerson = ds.Tables[0].Rows[0]["ContactPerson"].ToString();
                model.Telephone = ds.Tables[0].Rows[0]["Telephone"].ToString();
                model.Mobile = ds.Tables[0].Rows[0]["Mobile"].ToString();
                model.Fax = ds.Tables[0].Rows[0]["Fax"].ToString();
                model.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                model.Address = ds.Tables[0].Rows[0]["Address"].ToString();


                if (ds.Tables[0].Rows[0]["MaxShipDays"].ToString() != "")
                {
                    model.MaxShipDays = int.Parse(ds.Tables[0].Rows[0]["MaxShipDays"].ToString());
                }


                if (ds.Tables[0].Rows[0]["PlanDate"].ToString() != "")
                {
                    model.PlanDate = DateTime.Parse(ds.Tables[0].Rows[0]["PlanDate"].ToString());
                }
                model.ContractTerm = ds.Tables[0].Rows[0]["ContractTerm"].ToString();
                model.SAPSoNo = ds.Tables[0].Rows[0]["SAPSoNo"].ToString();
                model.ContractId = ds.Tables[0].Rows[0]["ContractId"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select OrderID,OrderNo,Creator,CreateDate,CardCode,CustomerID,BillAddress,ShipType,BillToCode,ShipToCode,ShipAddress,Freight,Currency,Discount,Rate,TotalAmount,BaseAmount,TaxAmount,DeliveryDate,ExpectDate,CloseDate,Remark,ApproveType,ApproveID,ApproveTime,CheckFlag,Confirmed,OrderStatus,ContractStatus,Address,Email,CntctCode ");
            strSql.Append(" FROM [Order] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获取订单详细
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public DataSet GetOrderDetail(string userName,string orderNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT *FROM View_OrderDetail WHERE UserName='" + userName + "' AND  ECOrderNum='" + orderNo + "'");
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string OrderNo, string CreateDateFrom, string CreateDateTo, int TotalAmountStart, int TotalAmountEnd,
            int ContractStatus, string ShipAddress, string ItemCode, string BrandName, string Description, string CreatorWhere, int OrderType,int languageID
            )
        {


            SqlParameter[] parameters = {
                    new SqlParameter("@OrderfldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@Sort", SqlDbType.Bit),
                    new SqlParameter("@OrderNo", SqlDbType.VarChar,100),
                    new SqlParameter("@TotalAmountStart", SqlDbType.Int),
                    new SqlParameter("@TotalAmountEnd", SqlDbType.Int),
                    new SqlParameter("@OrderStatus", SqlDbType.Int),
                    new SqlParameter("@ShipAddress", SqlDbType.VarChar,100),
                    new SqlParameter("@ItemCode", SqlDbType.VarChar,100),
                    new SqlParameter("@BrandName", SqlDbType.VarChar,100),
                    new SqlParameter("@Description", SqlDbType.VarChar, 255),
                    new SqlParameter("@CreatorWhere", SqlDbType.VarChar, 100),
                    new SqlParameter("@CreateDateFrom", SqlDbType.VarChar,30),
                    new SqlParameter("@CreateDateTo",SqlDbType.VarChar,30),
                    new SqlParameter("@OrderType", SqlDbType.Int),
                    new SqlParameter("@LanguageID",SqlDbType.Int)
                    };
            parameters[0].Value = "CreateDate";
            parameters[1].Value = PageSize;
            parameters[2].Value = PageIndex;
            parameters[3].Value = 1;
            parameters[4].Value = 1;
            parameters[5].Value = OrderNo;
            parameters[6].Value = TotalAmountStart;
            parameters[7].Value = TotalAmountEnd;
            parameters[8].Value = ContractStatus;
            parameters[9].Value = ShipAddress;
            parameters[10].Value = ItemCode;
            parameters[11].Value = BrandName;
            parameters[12].Value = Description;
            parameters[13].Value = CreatorWhere;
            parameters[14].Value = CreateDateFrom;
            parameters[15].Value = CreateDateTo;
            parameters[16].Value = OrderType;
            parameters[17].Value = languageID;
            return DbHelperSQL.RunProcedure("UP_Order_GetPageList", parameters, "ds");
        }
        /// <summary>
        /// 得到当前用户的历史订单数
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string getHisOrderCountByName(string name)
        {
            string sql = "SELECT  count(*)as num FROM [TimkenDB].[dbo].[Order] c inner join UserAccount a on a.CustomerID=c.CustomerID where UserName='{0}' ";
           return DbHelperSQL.GetData(string.Format(sql, name));
        }
        //<summary>
        //分页获取数据列表
        //</summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere, string OrderField, bool Direction,int languageID)
        {

            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@OrderfldName",SqlDbType.VarChar,255),
                    new SqlParameter("@StatfldName",SqlDbType.VarChar,255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    new SqlParameter("LanguageID",SqlDbType.Int)
                    };
            parameters[0].Value = "Order";
            parameters[1].Value = "*";
            parameters[2].Value = OrderField;
            parameters[3].Value = "";
            parameters[4].Value = PageSize;
            parameters[5].Value = PageIndex;
            parameters[6].Value = 1;
            parameters[7].Value = Direction ? 1 : 0;
            parameters[8].Value = strWhere;
            parameters[9].Value = languageID;
            return DbHelperSQL.RunProcedure("UP_GetRecordByPageOrder", parameters, "ds");
        }

        /// <summary>
        /// 返回订单状态列表
        /// </summary>
        /// <param name="languageID"></param>
        /// <returns></returns>
        public DataSet GetOrderStatus(int languageID) 
        {
            string sql = "Select * from OrderStatus where LanguageID=" + languageID.ToString();
            return DbHelperSQL.Query(sql);
        }
        public string GetOrderStatusName(OrderStatus orderStatusID, int languageID)
        {
            string sql = " select * from OrderStatus where id='" + ((int)orderStatusID).ToString() + "' and LanguageID=" + languageID.ToString();
            string result = "";
            using (SqlDataReader dr = DbHelperSQL.ExecuteReader(sql))
            if (dr.Read())
            {
                result = dr["Status"].ToString();
                dr.Close();
            }
            return result;
        }

        public DataTable getMyOrder(string user,string la)
        {
            SqlParameter[] parameters = {
                   new SqlParameter("@userName", SqlDbType.VarChar,50),
					new SqlParameter("@lagu", SqlDbType.VarChar,50)
                                        };
            parameters[0].Value = user;
            parameters[1].Value = la;
            DataSet ds = DbHelperSQL.RunProcedure("proc_GetOrder", parameters, "ds");
            if (ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }else{
                return null;
           }
        }

        public DataTable getMyOrderDetail(string code, string lagu)
        {
            SqlParameter[] parameters = {
                   new SqlParameter("@code", SqlDbType.VarChar,50),
					new SqlParameter("@lagu", SqlDbType.VarChar,50)
                                        };
            parameters[0].Value = code;
            parameters[1].Value = lagu;
            DataSet ds = DbHelperSQL.RunProcedure("proc_GetOrderUnpackByCode", parameters, "ds");
            if (ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            else
            {
                return null;
            }
        }
        #endregion  成员方法
    }
}
